home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / System / Sample 2.4 Think C distribution / pref.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-08-29  |  20.7 KB  |  687 lines  |  [TEXT/KAHL]

  1. /*______________________________________________________________________
  2.  
  3.     pref.c - Preferences Window Manager.
  4.     
  5.     Copyright © 1988, 1989, 1990 Northwestern University.  Permission is granted
  6.     to use this code in your own projects, provided you give credit to both
  7.     John Norstad and Northwestern University in your about box or document.
  8. _____________________________________________________________________*/
  9.  
  10. #include    <string.h>
  11. #include "utl.h"
  12. #include "rez.h"
  13. #include "glob.h"
  14. #include "wstm.h"
  15. #include "pref.h"
  16. #include "help.h"
  17. #include "misc.h"
  18.  
  19. #define nil 0
  20.  
  21. /*______________________________________________________________________
  22.  
  23.     Global Variables.
  24. _____________________________________________________________________*/
  25.  
  26.  
  27. static WindowPtr            PrefWindow = nil;        /* ptr to prefs window */
  28. static DialogRecord        PrefWRecord;            /* prefs window record */
  29. static WindowObject        PrefWindObject;        /* pref window object */
  30. static MenuHandle            RepMenu = nil;            /* handle to rep creator popup menu */
  31. static MenuHandle            DocMenu = nil;            /* handle to doc creator popup menu */
  32.     
  33. /*______________________________________________________________________
  34.  
  35.     Activate - Process an Activate Event.
  36. _____________________________________________________________________*/
  37.  
  38.  
  39. static void Activate (void)
  40.  
  41. {
  42.     TEActivate(((DialogPeek)PrefWindow)->textH);
  43. }
  44.     
  45. /*______________________________________________________________________
  46.  
  47.     Deactivate - Process a Deactivate Event.
  48. _____________________________________________________________________*/
  49.  
  50.  
  51. static void Deactivate (void)
  52.  
  53. {
  54.     TEDeactivate(((DialogPeek)PrefWindow)->textH);
  55.     misc_SetCursor();
  56. }
  57.  
  58. /*______________________________________________________________________
  59.  
  60.     Help - Process Mouse Down Event in Help Mode.
  61.     
  62.     Entry:        where = mouse down location, local coords.
  63. _____________________________________________________________________*/
  64.  
  65.  
  66. static void Help (Point where)
  67.  
  68. {
  69.     short                itemType;                /* dialog item type */
  70.     Handle            itemHandle;                /* dialog item handle */
  71.     Rect                box;                        /* dialog item rectangle */
  72.         
  73.     GetDItem(PrefWindow, prefsHorRule1, &itemType, &itemHandle, &box);
  74.     if (where.v < box.top) {
  75.         help_Open(tagPrefBeep);
  76.         return;
  77.     };
  78.     GetDItem(PrefWindow, prefsHorRule2, &itemType, &itemHandle, &box);
  79.     if (where.v < box.top) {
  80.         help_Open(tagPrefStation);
  81.         return;
  82.     };
  83.     GetDItem(PrefWindow, prefsHorRule3, &itemType, &itemHandle, &box);
  84.     if (where.v < box.top) {
  85.         help_Open(tagPrefSave);
  86.         return;
  87.     };
  88.     help_Open(tagPrefNotif);
  89. }
  90.  
  91. /*______________________________________________________________________
  92.  
  93.     Close - Close the Window
  94. _____________________________________________________________________*/
  95.  
  96.  
  97. static void Close (void)
  98.  
  99. {
  100.     Prefs.prefState.moved = PrefWindObject.moved;
  101.     wstm_Save(PrefWindow, &Prefs.prefState);
  102.     CloseDialog(PrefWindow);
  103.     PrefWindow = nil;
  104. }
  105.     
  106. /*______________________________________________________________________
  107.  
  108.     Edit - Process Edit Command.
  109.     
  110.     Entry:    cmd = which Edit command.
  111. _____________________________________________________________________*/
  112.  
  113.  
  114. static void Edit (EditCmd cmd)
  115.  
  116. {
  117.     short                item;                        /* dialog item number */
  118.     TEHandle            textH;                    /* handle to TextEdit record */
  119.     short                selSize;                    /* size of selected part of item */
  120.     short                textLen;                    /* text length */
  121.     long                scrapLen;                /* size of scrap */
  122.     Handle            scrapHandle;            /* handle to scrap */
  123.     char                scrapChar;                /* scrap character */
  124.             
  125.     switch (cmd) {
  126.         case cutCmd:
  127.             DlgCut(PrefWindow);
  128.             ZeroScrap();
  129.             TEToScrap();
  130.             break;
  131.         case copyCmd:
  132.             DlgCopy(PrefWindow);
  133.             ZeroScrap();
  134.             TEToScrap();
  135.             break;
  136.         case pasteCmd:
  137.             TEFromScrap();
  138.             item = ((DialogPeek)PrefWindow)->editField + 1;
  139.             textH = ((DialogPeek)PrefWindow)->textH;
  140.             selSize = (**textH).selEnd - (**textH).selStart;
  141.             textLen = (**textH).teLength;
  142.             scrapLen = TEGetScrapLen();
  143.             if ( item == prefsBeep) {
  144.                 /* Number of beeps field - beep and return if there would 
  145.                     be more than two digits in the field after the paste. */
  146.                 if (textLen + scrapLen - selSize > 2) {
  147.                     SysBeep(beepDuration);
  148.                     return;
  149.                 };
  150.                 /* Beep and return if the scrap contains a non-digit. */
  151.                 scrapHandle = TEScrapHandle();
  152.                 while (scrapLen--) {
  153.                     scrapChar = *(*scrapHandle + scrapLen);
  154.                     if (scrapChar < '0' || scrapChar > '9') {
  155.                         SysBeep(beepDuration);
  156.                         return;
  157.                     };
  158.                 };
  159.             } else {
  160.                 /* File creator type field - beep and return if there would
  161.                     be more than four characters in the field after the paste. */
  162.                 if (textLen + scrapLen - selSize > 4) {
  163.                     SysBeep(beepDuration);
  164.                     return;
  165.                 };
  166.             };
  167.             DlgPaste(PrefWindow);
  168.             break;
  169.         case clearCmd:
  170.             DlgDelete(PrefWindow);
  171.             break;
  172.     };
  173. }    
  174.     
  175. /*______________________________________________________________________
  176.  
  177.     Adjust - Adjust Menus.
  178. _____________________________________________________________________*/
  179.  
  180.  
  181. static void Adjust (void)
  182.  
  183. {
  184.     MenuHandle                fileM;                    /* handle to file menu */
  185.     MenuHandle                editM;                    /* handle to edit menu */
  186.     MenuHandle                scanM;                    /* handle to scan menu */
  187.     
  188.     fileM = GetMHandle(fileMID);
  189.     editM = GetMHandle(editMID);
  190.     scanM = GetMHandle(scanMID);
  191.     EnableItem(fileM, closeCommand);
  192.     DisableItem(fileM, saveAsCommand);
  193.     DisableItem(fileM, pageSetupCommand);
  194.     DisableItem(fileM, printCommand);
  195.     DisableItem(fileM, printOneCommand);
  196.     if (Scanning) {
  197.         DisableItem(scanM, 0);
  198.     } else {
  199.         EnableItem(scanM, 0);
  200.     };
  201.     DisableItem(editM, undoCommand);
  202.     EnableItem(editM, cutCommand);
  203.     EnableItem(editM, copyCommand);
  204.     EnableItem(editM, pasteCommand);
  205.     EnableItem(editM, clearCommand);
  206.     EnableItem(editM, 0);
  207. }
  208.  
  209. /*______________________________________________________________________
  210.  
  211.     Periodic - Handle Periodic Tasks.
  212. _____________________________________________________________________*/
  213.  
  214.  
  215. static void Periodic (void)
  216.  
  217. {
  218.     Point                mouseLoc;            /* mouse location */
  219.     short                itemType;            /* dialog item type */
  220.     Handle            itemHandle;            /* dialog item handle */
  221.     Rect                beepBox;                /* beep count textedit item rectangle */
  222.     Rect                repTypeBox;            /* report type textedit item rectangle */
  223.     Rect                docTypeBox;            /* doc type textedit item rectangle */
  224.     
  225.     if (FrontWindow() != PrefWindow || HelpMode) return;
  226.     SetPort(PrefWindow);
  227.     GetMouse(&mouseLoc);
  228.     GetDItem(PrefWindow, prefsBeep, &itemType, &itemHandle, &beepBox);
  229.     GetDItem(PrefWindow, prefsRepType, &itemType, &itemHandle, &repTypeBox);
  230.     GetDItem(PrefWindow, prefsDocType, &itemType, &itemHandle, &docTypeBox);
  231.     if (PtInRect(mouseLoc, &beepBox) || PtInRect(mouseLoc, &repTypeBox) ||
  232.         PtInRect(mouseLoc, &docTypeBox)) {
  233.         SetCursor(*IBeamCurs);
  234.     } else {
  235.         InitCursor();
  236.     };
  237. }
  238.  
  239. /*______________________________________________________________________
  240.  
  241.     DialogPre - Preprocess Dialog Event
  242.     
  243.     Entry:        key = key pressed.
  244.     
  245.     Exit:            function result = true if event should be processed,
  246.                         false if it should be discarded.
  247. _____________________________________________________________________*/
  248.  
  249.  
  250. static Boolean DialogPre (short key)
  251.  
  252. {
  253.     short                item;                        /* dialog item number */
  254.     TEHandle            textH;                    /* handle to TextEdit record */
  255.     short                selSize;                    /* size of selected part of item */
  256.     short                textLen;                    /* text length */
  257.         
  258.     if (key == deleteKey || key == tabKey ||
  259.         key == leftArrow || key == rightArrow) return true;
  260.     item = ((DialogPeek)PrefWindow)->editField + 1;
  261.     textH = ((DialogPeek)PrefWindow)->textH;
  262.     selSize = (**textH).selEnd - (**textH).selStart;
  263.     textLen = (**textH).teLength;
  264.     if (item == prefsBeep) {
  265.         /* Number of beeps field - beep and return false if the key
  266.             is not a digit, or if there would be more than two digits in
  267.             the field after the key is processed. */
  268.         if (key < '0' || key > '9' || textLen + 1 - selSize > 2) {
  269.             SysBeep(beepDuration);
  270.             return false;
  271.         };
  272.     } else {
  273.         /* File creator type field - beep and return false if there would
  274.             be more than four characters in the field after the key is
  275.             processed. */
  276.         if (textLen + 1 - selSize > 4) {
  277.             SysBeep(beepDuration);
  278.             return false;
  279.         };
  280.     };
  281.     return true;
  282. }
  283.  
  284. /*______________________________________________________________________
  285.  
  286.     GetPopInfo - Get Pop Up Menu Info.
  287.     
  288.     Entry:    popItem = item number of popup menu user item.
  289.                 creType = creator type.
  290.     
  291.     Exit:        theMenu = handle to menu.
  292.                 numItems = number of items in menu.
  293.                 creList = handle to creator type list.
  294.                 creIndex = index in menu of application name.
  295. _____________________________________________________________________*/
  296.  
  297.  
  298. static void GetPopInfo (short popItem, OSType creType,
  299.     MenuHandle *theMenu, short *numItems,
  300.     OSType ***creList, short *creIndex)
  301.     
  302. {
  303.     short        inx;                /* index in menu */
  304.  
  305.     if (popItem == prefsRepPop) {
  306.         if (!RepMenu) RepMenu = GetMenu(prefsRepMenuID);
  307.         *creList = (OSType**)GetResource('CREA', prefsRepCreaID);
  308.         *theMenu = RepMenu;
  309.     } else {
  310.         if (!DocMenu) DocMenu = GetMenu(prefsDocMenuID);
  311.         *creList = (OSType**)GetResource('CREA', prefsDocCreaID);
  312.         *theMenu = DocMenu;
  313.     };
  314.     *numItems = CountMItems(*theMenu);
  315.     for (inx = 0; inx < *numItems; inx++) {
  316.         if (creType == *(**creList + inx)) break;
  317.     };
  318.     if (inx < *numItems) inx++;
  319.     *creIndex = inx;
  320. }
  321.  
  322. /*______________________________________________________________________
  323.  
  324.     PopUp - Pop Up Menu.
  325.     
  326.     Entry:    popItem = item number of popup menu user item.
  327.                 labelItem = item number of label static text item.
  328.                 editItem = item number of edittext item.
  329.                 menuID = resource id of popup menu.
  330.                 creType = pointer to Prefs creator type field.
  331.                 otherType = pointer to Prefs other creator type field.
  332. _____________________________________________________________________*/
  333.  
  334.  
  335. static void PopUp (short popItem, short labelItem, short editItem, short menuID,
  336.     OSType *creType, OSType *otherType)
  337.  
  338. {
  339.     MenuHandle        theMenu;                /* handle to menu */
  340.     short                itemType;            /* dialog item type */
  341.     Handle            itemHandle;            /* dialog item handle */
  342.     Rect                labelBox;            /* label rectangle */
  343.     Rect                popBox;                /* popup menu rectangle */
  344.     Rect                typeBox;                /* textedit rectangle */
  345.     Point                popPoint;            /* location of popup menu, global coords */
  346.     long                result;                /* PopUpMenuSelect result */
  347.     OSType            **creList;            /* handle to list of creator types */
  348.     short                numItems;            /* number of items in list */
  349.     short                oldIndex;            /* index in list of old selected item */
  350.     short                newIndex;            /* index in list of new selected item */
  351.     char                itemText[5];        /* creator type */
  352.     
  353.     /* Return if the system does not support popup menus. */
  354.     
  355.     if (!utl_SysHasPopUp()) return;
  356.     
  357.     /* Get popup info. */
  358.     
  359.     GetPopInfo(popItem, *creType, &theMenu, &numItems, &creList, &oldIndex);
  360.     
  361.     /* Check the currently selected item, and invert the label rectangle. */
  362.     
  363.     CheckItem(theMenu, oldIndex, true);
  364.     GetDItem(PrefWindow, labelItem, &itemType, &itemHandle, &labelBox);
  365.     InvertRect(&labelBox);
  366.     
  367.     /* Get the location of the popup menu and convert it to global coords. */
  368.     
  369.     GetDItem(PrefWindow, popItem, &itemType, &itemHandle, &popBox);
  370.     popPoint = *(Point*)&popBox;
  371.     LocalToGlobal(&popPoint);
  372.     
  373.     /* Present the popup menu. */
  374.     
  375.     InsertMenu(theMenu, -1);
  376.     result = PopUpMenuSelect(theMenu, popPoint.v, popPoint.h, oldIndex);
  377.     DeleteMenu(menuID);
  378.     
  379.     /* Uncheck the old selected item, and uninvert the lable rectangle. */
  380.     
  381.     CheckItem(theMenu, oldIndex, false);
  382.     InvertRect(&labelBox);
  383.     
  384.     /* Process the new selected item. */
  385.     
  386.     if ((result >> 16) & 0xffff) {
  387.         GetDItem(PrefWindow, editItem, &itemType, &itemHandle, &typeBox);
  388.         newIndex = (result & 0xffff);
  389.         if (oldIndex == numItems) {
  390.             GetIText(itemHandle, (StringPtr)itemText);
  391.             *otherType = '    ';
  392.             memcpy(otherType, itemText+1, *itemText);
  393.         };
  394.         if (newIndex == numItems) {
  395.             *creType = *otherType;
  396.         } else {
  397.             *creType = *(*creList + newIndex - 1);
  398.         };
  399.         memcpy(itemText+1, creType, 4);
  400.         *itemText = 4;
  401.         SetIText(itemHandle, (StringPtr)itemText);
  402.         InvalRect(&popBox);
  403.     };
  404. }
  405.  
  406. /*______________________________________________________________________
  407.  
  408.     DialogPost - Postprocess Dialog Event
  409.     
  410.     Entry:        item = dialog item number.
  411. _____________________________________________________________________*/
  412.  
  413.  
  414. static void DialogPost (short item)
  415.  
  416. {
  417.     short                itemType;                /* dialog item type */
  418.     Handle            itemHandle;                /* dialog item handle */
  419.     Rect                box;                        /* dialog item rectangle */
  420.     char                itemText[5];            /* dialog item text */
  421.     long                beepCount;                /* beep count */
  422.         
  423.     switch (item) {
  424.         case prefsBeep:
  425.             GetDItem(PrefWindow, prefsBeep, &itemType, &itemHandle, &box);
  426.             GetIText(itemHandle, (StringPtr)itemText);
  427.             StringToNum((StringPtr)itemText, &beepCount);
  428.             Prefs.beepCount = beepCount;
  429.             break;
  430.         case prefsStation:
  431.             Prefs.scanningStation = !Prefs.scanningStation;
  432.             GetDItem(PrefWindow, prefsStation, &itemType, &itemHandle, &box);
  433.             SetCtlValue((ControlHandle)itemHandle, Prefs.scanningStation);
  434.             GetDItem(PrefWindow, prefsScan, &itemType, &itemHandle, &box);
  435.             HiliteControl((ControlHandle)itemHandle, 
  436.                 Prefs.scanningStation ? 0 : 255);
  437.             GetDItem(PrefWindow, prefsDisinfect, &itemType, &itemHandle, &box);
  438.             HiliteControl((ControlHandle)itemHandle, 
  439.                 Prefs.scanningStation ? 0 : 255);
  440.             break;
  441.         case prefsScan:
  442.         case prefsDisinfect:
  443.             GetDItem(PrefWindow, prefsScan + Prefs.scanningStationOp,
  444.                 &itemType, &itemHandle, &box);
  445.             SetCtlValue((ControlHandle)itemHandle, 0);
  446.             Prefs.scanningStationOp = item - prefsScan;
  447.             GetDItem(PrefWindow, item, &itemType, &itemHandle, &box);
  448.             SetCtlValue((ControlHandle)itemHandle, 1);
  449.             break;
  450.         case prefsRepPop:
  451.             PopUp(prefsRepPop, prefsRepLabel, prefsRepType, prefsRepMenuID,
  452.                 &Prefs.repCreator, &Prefs.repOtherCre);
  453.             break;
  454.         case prefsDocPop:
  455.             PopUp(prefsDocPop, prefsDocLabel, prefsDocType, prefsDocMenuID,
  456.                 &Prefs.docCreator, &Prefs.docOtherCre);            
  457.             break;
  458.         case prefsRepType:
  459.             GetDItem(PrefWindow, prefsRepType, &itemType, &itemHandle, &box);
  460.             GetIText(itemHandle, (StringPtr)itemText);
  461.             Prefs.repCreator = '    ';
  462.             memcpy(&Prefs.repCreator, itemText+1, *itemText);
  463.             GetDItem(PrefWindow, prefsRepPop, &itemType, &itemHandle, &box);
  464.             InvalRect(&box);
  465.             break;
  466.         case prefsDocType:
  467.             GetDItem(PrefWindow, prefsDocType, &itemType, &itemHandle, &box);
  468.             GetIText(itemHandle, (StringPtr)itemText);
  469.             Prefs.docCreator = '    ';
  470.             memcpy(&Prefs.docCreator, itemText+1, *itemText);
  471.             GetDItem(PrefWindow, prefsDocPop, &itemType, &itemHandle, &box);
  472.             InvalRect(&box);
  473.             break;
  474.         case prefsDiamond:
  475.         case prefsIcon:
  476.         case prefsAlert:
  477.             GetDItem(PrefWindow, prefsDiamond + Prefs.notifOption,
  478.                 &itemType, &itemHandle, &box);
  479.             SetCtlValue((ControlHandle)itemHandle, 0);
  480.             Prefs.notifOption = item - prefsDiamond;
  481.             GetDItem(PrefWindow, item, &itemType, &itemHandle, &box);
  482.             SetCtlValue((ControlHandle)itemHandle, 1);
  483.             break;
  484.     };
  485. }
  486.  
  487. /*______________________________________________________________________
  488.  
  489.     DrawPopUp - Draw PopUp User Item.
  490.     
  491.     Entry:        theWindow = pointer to dialog window.
  492.                     itemNo = item number.
  493. _____________________________________________________________________*/
  494.  
  495.  
  496. static pascal void DrawPopUp (WindowPtr theWindow, short itemNo)
  497.  
  498. {
  499.     MenuHandle    theMenu;                /* handle to menu */
  500.     short            itemType;            /* item type */
  501.     Handle        itemHandle;            /* item handle */
  502.     Rect            box;                    /* item rectangle */
  503.     OSType        **creList;            /* handle to list of creator types */
  504.     short            numItems;            /* number of items in list */
  505.     short            creIndex;            /* index in list of selected item */
  506.     Str255        appName;                /* application name */
  507.     PolyHandle    triangle;            /* handle to triangle polygon */
  508.     
  509.     /* Get the currently selected application name. */
  510.     
  511.     GetPopInfo(itemNo, 
  512.         itemNo == prefsRepPop ? Prefs.repCreator : Prefs.docCreator, 
  513.         &theMenu, &numItems, &creList, &creIndex);
  514.     GetItem(theMenu, creIndex, appName);
  515.     
  516.     /* Draw the currently selected application name. */
  517.     
  518.     GetDItem(theWindow, itemNo, &itemType, &itemHandle, &box);
  519.     box.left += 4;
  520.     TextBox((Ptr)appName+1, *appName, &box, teJustLeft);
  521.     box.left -= 4;
  522.  
  523.     /* Frame the rectangle and draw the drop shadow and triangle. */
  524.  
  525.     if (utl_SysHasPopUp()) {
  526.         InsetRect(&box, -1, -1);
  527.         FrameRect(&box);
  528.         MoveTo(box.right, box.top+2);
  529.         LineTo(box.right, box.bottom);
  530.         LineTo(box.left+2, box.bottom);
  531.         triangle = OpenPoly();
  532.         MoveTo(box.right - 14, (box.top + box.bottom - 5)>>1);
  533.         Line(10, 0);
  534.         Line(-5, 5);
  535.         Line(-5, -5);
  536.         ClosePoly();
  537.         PaintPoly(triangle);
  538.         KillPoly(triangle);
  539.     };
  540. }
  541.  
  542. /*______________________________________________________________________
  543.  
  544.     DimNotif - Dim Notificiation Section User Item.
  545.     
  546.     Entry:        theWindow = pointer to dialog window.
  547.                     itemNo = item number.
  548.                     
  549.     If the system does not support the Notification Manager, this user
  550.     item dims the entire section.
  551. _____________________________________________________________________*/
  552.  
  553.  
  554. static pascal void DimNotif (WindowPtr theWindow, short itemNo)
  555.  
  556. {
  557.     short            itemType;            /* item type */
  558.     Handle        itemHandle;            /* item handle */
  559.     Rect            box;                    /* item rectangle */
  560.     
  561.     if (!utl_SysHasNotMgr()) {
  562.         PenMode(patBic);
  563.         PenPat(&gray);
  564.         GetDItem(theWindow, prefsNotPict, &itemType, &itemHandle, &box);
  565.         PaintRect(&box);
  566.         GetDItem(theWindow, prefsNotTitle1, &itemType, &itemHandle, &box);
  567.         PaintRect(&box);
  568.         GetDItem(theWindow, prefsNotTitle2, &itemType, &itemHandle, &box);
  569.         PaintRect(&box);
  570.         GetDItem(theWindow, prefsNotTitle3, &itemType, &itemHandle, &box);
  571.         PaintRect(&box);
  572.         PenMode(patCopy);
  573.         PenPat(&black);
  574.     };
  575. }
  576.     
  577. /*______________________________________________________________________
  578.  
  579.     pref_Open - Open Pref Window.
  580. _____________________________________________________________________*/
  581.  
  582.  
  583. void pref_Open (void)
  584.  
  585. {
  586.     short                i;                    /* loop index */
  587.     short                itemType;        /* dialog item type */
  588.     Handle            itemHandle;                /* dialog item handle */
  589.     Rect                box;                /* dialog item rectangle */
  590.     char                itemText[5];    /* dialog item text */
  591.     
  592.     /* If the window is already open, activate it. */
  593.     
  594.     if (PrefWindow) {
  595.         SelectWindow(PrefWindow);
  596.         return;
  597.     };
  598.     
  599.     /* Get the pref window and restore its state. */
  600.     
  601.     PrefWindow = wstm_Restore(true, prefsWindID, (Ptr)&PrefWRecord,
  602.         &Prefs.prefState);
  603.     SetPort(PrefWindow);
  604.     
  605.     /* Initialize the window object. */
  606.     
  607.     ((WindowPeek)PrefWindow)->refCon = (long)&PrefWindObject;
  608.     PrefWindObject.windKind = prefWind;
  609.     PrefWindObject.moved = Prefs.prefState.moved;
  610.     PrefWindObject.update = nil;
  611.     PrefWindObject.activate = Activate;
  612.     PrefWindObject.deactivate = Deactivate;
  613.     PrefWindObject.resume = nil;
  614.     PrefWindObject.suspend = nil;
  615.     PrefWindObject.click = nil;
  616.     PrefWindObject.help = Help;
  617.     PrefWindObject.grow = nil;
  618.     PrefWindObject.zoom = nil;
  619.     PrefWindObject.key = nil;
  620.     PrefWindObject.close = Close;
  621.     PrefWindObject.disk = nil;
  622.     PrefWindObject.save = nil;
  623.     PrefWindObject.pageSetup = nil;
  624.     PrefWindObject.print = nil;
  625.     PrefWindObject.edit = Edit;
  626.     PrefWindObject.adjust = Adjust;
  627.     PrefWindObject.periodic = Periodic;
  628.     PrefWindObject.dialogPre = DialogPre;
  629.     PrefWindObject.dialogPost = DialogPost;
  630.     
  631.     /* Set the pointers to the user item handlers. */
  632.     
  633.     for (i = prefsFirstRule; i <= prefsLastRule; i++) {
  634.         GetDItem(PrefWindow, i, &itemType, &itemHandle, &box);
  635.         SetDItem(PrefWindow, i, itemType, (Handle)utl_FrameItem, &box);
  636.     };
  637.     GetDItem(PrefWindow, prefsRepPop, &itemType, &itemHandle, &box);
  638.     SetDItem(PrefWindow, prefsRepPop, itemType, (Handle)DrawPopUp, &box);
  639.     GetDItem(PrefWindow, prefsDocPop, &itemType, &itemHandle, &box);
  640.     SetDItem(PrefWindow, prefsDocPop, itemType, (Handle)DrawPopUp, &box);
  641.     GetDItem(PrefWindow, prefsDim, &itemType, &itemHandle, &box);
  642.     SetDItem(PrefWindow, prefsDim, itemType, (Handle)DimNotif, &box);
  643.     
  644.     /* Initialize the control values and hilite states. */
  645.     
  646.     GetDItem(PrefWindow, prefsStation, &itemType, &itemHandle, &box);
  647.     SetCtlValue((ControlHandle)itemHandle, Prefs.scanningStation);
  648.     if (utl_SysHasNotMgr()) {
  649.         GetDItem(PrefWindow, prefsDiamond + Prefs.notifOption, 
  650.             &itemType, &itemHandle, &box);
  651.         SetCtlValue((ControlHandle)itemHandle, 1);
  652.     } else {
  653.         for (i = prefsDiamond; i <= prefsAlert; i++) {
  654.             GetDItem(PrefWindow, i, &itemType, &itemHandle, &box);
  655.             HiliteControl((ControlHandle)itemHandle, 255);
  656.         };
  657.     };
  658.     GetDItem(PrefWindow, prefsScan, &itemType, &itemHandle, &box);
  659.     SetCtlValue((ControlHandle)itemHandle, 
  660.         Prefs.scanningStationOp == checkOp);
  661.     if (!Prefs.scanningStation) HiliteControl((ControlHandle)itemHandle, 255);
  662.     GetDItem(PrefWindow, prefsDisinfect, &itemType, &itemHandle, &box);
  663.     SetCtlValue((ControlHandle)itemHandle, 
  664.         false);
  665.     if (!Prefs.scanningStation) HiliteControl((ControlHandle)itemHandle, 255);
  666.     
  667.     /* Initialize the textedit fields. */
  668.     
  669.     GetDItem(PrefWindow, prefsRepType, &itemType, &itemHandle, &box);
  670.     memcpy(itemText+1, &Prefs.repCreator, 4);
  671.     *itemText = 4;
  672.     while (*(itemText + *itemText) == ' ') (*itemText)--;
  673.     SetIText(itemHandle, (StringPtr)itemText);
  674.     GetDItem(PrefWindow, prefsDocType, &itemType, &itemHandle, &box);
  675.     memcpy(itemText+1, &Prefs.docCreator, 4);
  676.     *itemText = 4;
  677.     SetIText(itemHandle, (StringPtr)itemText);
  678.     GetDItem(PrefWindow, prefsBeep, &itemType, &itemHandle, &box);
  679.     NumToString(Prefs.beepCount, (StringPtr)itemText);
  680.     SetIText(itemHandle, (StringPtr)itemText);
  681.     SelIText(PrefWindow, prefsBeep, 0, 32767);
  682.     
  683.     /* Show the window. */
  684.     
  685.     utl_LockControls(PrefWindow);
  686.     ShowWindow(PrefWindow);
  687. }